<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
</head>
<body>
<script src="__PUBLIC__/layui/layui.js"></script>
<div style="margin-top: 20px;">
</div>

<div id="classifybox">

    <div class="layui-form-item classifychild" >
        <label class="layui-form-label"></label>
        <div class="layui-input-inline person" style="width: 400px">
            <input type="hidden" id="code1" value="{$code}">
            <a class="layui-btn layui-btn-xs layui-btn-warm flushPrice" style="margin-left: 3px;margin-right: 0;font-size:12px;background:#ff0000">手动刷新</a>
        </div>
    </div>

    {volist name="data" id="vo"}
    <div class="layui-form-item classifychild" >
        <label class="layui-form-label">套餐名称</label>
        <div class="layui-input-inline person" style="width: 400px">
            <div class="layui-input-inline" style="width: 400px;padding-bottom: 15px">
                <input class="gradeTitle" value="{$vo.gradeTitle}" class="layui-input" type="text">
                <input value="{$vo.specs_ename}" readonly="readonly" disabled type="text" style="margin-top:5px;">
                <input type="hidden" class="gradeCode" value="{$vo.gradeCode}">
                <input type="hidden" class="code" value="{$vo.code}">
                <input type="hidden" class="specs_name" value="{$vo.specs_name}">
            </div>
            <div class="layui-input-inline" style="width: 400px;padding-bottom: 15px">
                <a class="layui-btn layui-btn-xs layui-btn-warm changeName" style="margin-left: 3px;margin-right: 0;font-size:12px;background: #51a954">修改</a>
                <a class="layui-btn layui-btn-xs layui-btn-warm resetName" data-name="{$vo.specs_name}" style="margin-right: 0;font-size:12px;background: darkslategrey">重置</a>
            </div>
            <div class="layui-form-item personchild">
                <div class="layui-col-xs2">
                    <div id="{$vo.time_id}"></div>
                </div>
            </div>
            <div id="price_div_{$vo.time_id}"></div>
        </div>
    </div>

    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            var code = "{$vo.code}";
            var time_id = "{$vo.time_id}";
            var gradeCode = "{$vo.gradeCode}";
            var date_arr = '<?php echo json_encode($vo["date_arr"]); ?>';
            var jsonObj = JSON.parse(date_arr);//转换为json对象
            for(var item in jsonObj){
                jsonObj[item] = "<span style='color:red;'>" + jsonObj[item] + "</span>";
            }

            laydate.render({
                elem: '#'+time_id,
                position: 'static',
                showBottom: false,
                trigger:'click',
                mark: jsonObj,
                change: function(value){
                    $.ajax({
                        url:"{:url('admin/goods/getPriceFromDate')}",
                        type: "POST",
                        async:false,
                        data:{ code:code, gradeCode:gradeCode, date:value },
                        success:function(data) {
                            var html = '';
                            if(data.length>0){
                                html += '<div class="layui-form-item personchild" style="width:600px;">\n' +
                                    '<div class=" layui-col-xs2">\n' +
                                    '<input value="客户群体" readonly="readonly" class="layui-input layui-col-xs5" type="text" style="border-style:none">\n' +
                                    '</div>\n' +
                                    '<div class="layui-col-xs1" style="text-align: center; line-height: 38px">~</div>\n' +
                                    '<div class=" layui-col-xs2">\n' +
                                    '<input readonly="readonly" value="年龄段" class="layui-input layui-col-xs5" type="text" style="border-style:none">\n' +
                                    '</div>\n' +
                                    '<div class="layui-col-xs1" style="text-align: center; line-height: 38px">~</div>\n' +
                                    '<div class=" layui-col-xs2">\n' +
                                    '<input readonly="readonly" value="销售价$" class="layui-input layui-col-xs5" type="text" style="border-style:none">\n' +
                                    '</div>\n' +
                                    '<div class="layui-col-xs1" style="text-align: center; line-height: 38px">~</div>\n' +
                                    '<div class=" layui-col-xs3">\n' +
                                    '<input readonly="readonly" value="采购价$（含5%税）" class="layui-input layui-col-xs5" type="text" style="border-style:none">\n' +
                                    '</div>\n' +
                                    '</div>';
                            }
                            for(var i=0;i<data.length;i++){
                                var title = data[i].title;
                                var age = data[i].age;
                                var price = data[i].price;
                                var merchantNetPrice = data[i].merchantNetPrice;
//                                //采购价增加税点 5%
//                                merchantNetPrice = merchantNetPrice*105;
//                                merchantNetPrice = Math.round(merchantNetPrice)/100;
                                html += '<div class="layui-form-item personchild">\n' +
                                    '<div class=" layui-col-xs3">\n' +
                                    '<input value="'+title+'" readonly="readonly" class="layui-input layui-col-xs5" type="text">\n' +
                                    '</div>\n' +
                                    '<div class="layui-col-xs1" style="text-align: center; line-height: 38px">~</div>\n' +
                                    '<div class=" layui-col-xs2">\n' +
                                    '<input readonly="readonly" value="'+age+'" class="layui-input layui-col-xs5" type="text">\n' +
                                    '</div>\n' +
                                    '<div class="layui-col-xs1" style="text-align: center; line-height: 38px">~</div>\n' +
                                    '<div class=" layui-col-xs2">\n' +
                                    '<input readonly="readonly" value="'+price+'" class="layui-input layui-col-xs5" type="text">\n' +
                                    '</div>\n' +
                                    '<div class="layui-col-xs1" style="text-align: center; line-height: 38px">~</div>\n' +
                                    '<div class=" layui-col-xs2">\n' +
                                    '<input readonly="readonly" value="'+merchantNetPrice+'" class="layui-input layui-col-xs5" type="text">\n' +
                                    '</div>\n' +
                                    '</div>';
                            }
                            $("#price_div_"+time_id).html(html);
                        }
                    });
                }
            });
        });
    </script>
    {/volist}
</div>




<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
    var message;
    layui.config({
        base: '__JS__/',
        version: '1.0.1'
    }).use(['app', 'message'], function() {
        var app = layui.app,
            $ = layui.jquery,
            layer = layui.layer;
        //将message设置为全局以便子页面调用
        message = layui.message;
        //主入口
        app.set({
            type: 'iframe'
        }).init();
    });
</script>
<script>
    //修改套餐名
    $('.changeName').click(function() {
        var title = $(this).parent().parent().find(".gradeTitle").val();
        var code = $(this).parent().parent().find(".code").attr("value");
        var gradeCode = $(this).parent().parent().find(".gradeCode").attr("value");
        var specs_name = $(this).parent().parent().find(".specs_name").attr("value");
        if(title==''){
            layer.msg("套餐名不能为空");
            return false;
        }
        $.ajax({
            url: "{:url('admin/goods/changeName')}",
            type: "POST",
            data: {
                title: title,
                gradeCode: gradeCode,
                code: code,
                specs_name: specs_name
            },
            success: function (res) {
                layer.msg(res.msg);
            }
        });
        return false;
    });

    //重置套餐名
    $('.resetName').click(function() {
        var specs_name = $(this).attr("data-name");
        var code = $(this).parent().parent().find(".code").attr("value");
        var gradeCode = $(this).parent().parent().find(".gradeCode").attr("value");
        var gradeTitle = $(this).parent().parent().find(".gradeTitle");
        $.ajax({
            url: "{:url('admin/goods/changeName')}",
            type: "POST",
            data: {
                title: specs_name,
                gradeCode: gradeCode,
                code: code,
                specs_name: specs_name
            },
            success: function () {
                gradeTitle.attr("value",specs_name);
                gradeTitle.val(specs_name);
                layer.msg("已经重置套餐名");
            }
        });
        return false;
    });



    $('.flushPrice').click(function() {
        var code = $("#code1").attr("value");
        layer.msg("请稍等几秒，等候页面刷新");
        var flush_load = layer.load(2,{
            shade: [0.5, '#000'] //0.1透明度的白色背景
        });
        $.ajax({
            url: "{:url('admin/goods/flushPrice')}",
            async: true,
            type: "POST",
            data: {
                code: code
            },
            success: function (res) {
                layer.close(flush_load);
                location.reload();
            }
        });
        return false;
    });


</script>



</body>
</html>
